package pilgun.eshop.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


public class Order {

	int id;
	User user;
	Cart cart;
	List<OrderStatus> statusList = new ArrayList<OrderStatus>();
	Date orderDate;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public Cart getCart() {
		return cart;
	}
	public void setCart(Cart cart) {
		this.cart = cart;
	}
	public List<OrderStatus> getStatusList() {
		return statusList;
	}
	public void setStatusList(List<OrderStatus> statusList) {
		this.statusList = statusList;
	}
	public void addToStatusList(OrderStatus status)	{
		statusList.add(status);
	}
	
	public Date getOrderDate() {
		return orderDate;
	}
	public void setOrderDate(Date orderDate) {
		this.orderDate = new Date(orderDate.getTime());
	}
	@Override
	public String toString() {
		return "Order [id=" + id + ", user=" + user + ", cart=" + cart
				+ ", statusList=" + statusList + ", orderDate=" + orderDate
				+ "]";
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cart == null) ? 0 : cart.hashCode());
		result = prime * result
				+ ((orderDate == null) ? 0 : orderDate.hashCode());
		result = prime * result
				+ ((statusList == null) ? 0 : statusList.hashCode());
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj){
			return true;
		}
		if (obj == null){
			return false;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		Order other = (Order) obj;
		if (cart == null) {
			if (other.cart != null){
				return false;
			}
		}else{
			if (!cart.equals(other.cart)){
				return false;
			}
		}
		if (orderDate == null) {
			if (other.orderDate != null){
				return false;
			}
		}else{
			if (!orderDate.equals(other.orderDate)){
				return false;
			}
		}
		if (statusList == null) {
			if (other.statusList != null){
				return false;
			}
		}else{ 
			if (!statusList.equals(other.statusList)){
				return false;
			}
		}
		if (user == null) {
			if (other.user != null){
				return false;
			}
		}else{ 
			if (!user.equals(other.user)){
				return false;
			}
		}
		return true;
	}
	
}
